﻿using System;
using nRoute.Components.Composition;
using nRoute.Utilities;
using nRoute.ViewModels;

namespace nRoute.Mapping
{
    public class DefaultViewModelLocator
		 : ResourceLocatorBase
    {
        private readonly Type _viewType;
        private readonly Type _viewModelType;

        public DefaultViewModelLocator(Type viewType, Type viewModelType)
        {
            Guard.ArgumentNotNull(viewType, "viewType");
            Guard.ArgumentNotNull(viewModelType, "viewModelType");

            _viewType = viewType;
            _viewModelType = viewModelType;
        }

        public Type ViewType
        {
            get { return _viewType; }
        }

        public Type ViewModelType
        {
            get { return _viewModelType; }
        }

#region Overrides

        protected override object GetInstance(ITypeBuilder typeBuilder)
        {
            // note we can pass along the typeBuilder, since we are not caching the ViewModelProvider type.. so no leaks
            return new ViewModelProvider(typeBuilder, this.ViewType, this.ViewModelType);
        }

#endregion

    }
}